package com.vcredit.creditcat.service;

import java.net.MalformedURLException;
import java.net.URL;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.tempuri.PDFGeneration;
import org.tempuri.PDFGenerationSoap;

@Component
public class GetWebApiFromVBS {
	private Logger logger = LoggerFactory.getLogger(GetWebApiFromVBS.class);
	
	@Value("${pdf.generation.url}")
	private String PDF_GENERATION_URL;
	
	private static PDFGenerationSoap pdfGenerationSoap = null;
	
	public PDFGenerationSoap getPDFGenerationSoap() throws Exception {
		if (pdfGenerationSoap == null) {
			PDFGeneration pdfGeneration = null;
			try {
				pdfGeneration = new PDFGeneration(new URL(PDF_GENERATION_URL));
				GetWebApiFromVBS.pdfGenerationSoap = pdfGeneration.getPDFGenerationSoap();
			} catch (MalformedURLException e) {
				e.printStackTrace();
				logger.error(e.toString());
			} catch (Exception e) {
				e.printStackTrace();
				logger.error(e.toString());
				throw new Exception("Error when load VBS web service--PDFGeneration");
			}
		}
		return pdfGenerationSoap;
	}
}
